package com.bsit.obu.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;


import com.bsit.obu.R;
import com.bsit.obu.adapter.NomalItemAdapter;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ListPromptDialog extends Dialog {

	@BindView(R.id.win_prompt_list)
	protected ListView contentView;
	private List<String> content;
	protected View view;
	protected onSubmitListener onSubmit;
	private NomalItemAdapter nomalItemAdapter;
	Context context;
	private int index;

	public ListPromptDialog(Context context, List<String> content,
							onSubmitListener onSubmit, int selectItemPosition) {
		super(context, R.style.dialog);
		this.context = context;
		this.content = content;
		this.onSubmit = onSubmit;
		index = selectItemPosition;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		view = inflater.inflate(R.layout.dialog_list_prompt, null);
		ButterKnife.bind(this, view);
		nomalItemAdapter = new NomalItemAdapter(context, content, index);
		contentView.setAdapter(nomalItemAdapter);
		contentView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				if(onSubmit != null){
					onSubmit.onSubmit(content.get(position));
					dismiss();
				}
			}
		});
//		ButterKnife.bind(this, view);
		this.setContentView(view);
	}

	public void reflshView(int index){
		nomalItemAdapter.refreshView(index);
	}

	public interface onSubmitListener{
		void onSubmit(String text);
	}
}
